package nz.co.doherty.gwtpbreadcrumbs.server.handler.customer;

import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.customer.CustomerCreateAction;
import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.customer.CustomerCreateResult;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.philbeaudoin.gwtp.dispatch.server.ExecutionContext;
import com.philbeaudoin.gwtp.dispatch.server.actionHandler.ActionHandler;
import com.philbeaudoin.gwtp.dispatch.shared.ActionException;

public class CustomerCreateHandler implements
		ActionHandler<CustomerCreateAction, CustomerCreateResult> {

	
	@Override
	public CustomerCreateResult execute(CustomerCreateAction action,
			ExecutionContext context) throws ActionException {
		
		Objectify ofy = ObjectifyService.begin();
		return new CustomerCreateResult(ofy.put(action
				.getCustomer()));
		
	}

	@Override
	public void undo(CustomerCreateAction action, CustomerCreateResult result,
			ExecutionContext context) throws ActionException {
		// TODO Auto-generated method stub

	}

	@Override
	public Class<CustomerCreateAction> getActionType() {		
		return CustomerCreateAction.class;
	}

}
